#include "stdafx.h"
#include "Camera.h"

using namespace MomogenkyouSystem;

Camera::Camera()
{
}

Camera::~Camera()
{
}

void Camera::SetPositionLook(const float4 & Position, const float4 & Look)
{
	m_vPosition = Position;
	m_vLook = Look;
	CalculateView();
}

void Camera::SetPosition(const float4 & Position)
{
	m_vPosition = Position;
	CalculateView();
}

void Camera::SetLook(const float4 & Look)
{
	m_vLook = Look;
	CalculateView();
}

void Camera::CalculateView()
{
	D3DXVec3Subtract((float3 *)&m_vFront, (float3 *)&m_vLook, (float3 *)&m_vPosition);

	//D3DXVec3Cross((float3 *)&m_vRight,	(float3 *)&m_vFront, (float3 *)&m_vUp);
	D3DXVec3Cross((float3 *)&m_vRight,	(float3 *)&m_vFront, &MomogenkyouHelper::FLOAT3_UNIT_Y);
	D3DXVec3Cross((float3 *)&m_vUp,		(float3 *)&m_vRight, (float3 *)&m_vFront);

	D3DXVec3Normalize((float3 *)&m_vFront,	(float3 *)&m_vFront);
	D3DXVec3Normalize((float3 *)&m_vRight,	(float3 *)&m_vRight);
	D3DXVec3Normalize((float3 *)&m_vUp,		(float3 *)&m_vUp);
	
	D3DXMatrixLookAtLH(&matView, (float3 *)&m_vPosition, (float3 *)&m_vLook, (float3 *)&m_vUp);
	GraphicsSystem::Device->SetTransform(D3DTS_VIEW, &matView);
}


void Camera::CalculatePerspective(const float & FOV, const float & AspectRatio, const float & Near, const float & Far)
{
	D3DXMatrixPerspectiveFovLH(&matProjection, FOV, AspectRatio, Near, Far);
	GraphicsSystem::Device->SetTransform(D3DTS_PROJECTION, &matProjection);
}

void Camera::CalculateOrthographic(const float & Width, const float & Height, const float & Near, const float & Far)
{
	D3DXMatrixOrthoRH(&matProjection, Width, Height, Near, Far);
	GraphicsSystem::Device->SetTransform(D3DTS_PROJECTION,	&matProjection);
	GraphicsSystem::Device->SetTransform(D3DTS_VIEW,		&MomogenkyouHelper::MATRIX_IDENTITY);
}